package com.ranjiaqi.thread07;

/**
 * @ClassName SubThread
 * @Description TODO
 * @Author hp
 * @Date 2021/6/28 18:55
 * @Version 1.0
 **/
public class SubThread implements Runnable {
    private int ticket = 100;

    public synchronized void sell(){
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (ticket > 0) {
            System.out.println(Thread.currentThread().getName() + "售出第" + ticket-- + "张票");
        }
    }

    @Override
    public void run() {
        while (true)
            sell();
    }
}

